<script type="text/javascript">
document.getElementById("headingTilte").style.display="none";
document.getElementById("ToolBarTable").style.display="none";
var isDriverInstalled=false;
var currentID=null;
var catSelected=null;
var selectedYahooID="";
var currentLevel=0;
var goBackTab=0;
var selectedColor="#fe9900";
var numberLevel=1;
try{
	var ObjDoc = new ActiveXObject("BrssCom.Document");
	if(ObjDoc){
		isDriverInstalled=true;
	}
}
catch(e){
	isDriverInstalled=false;
	// QuangLV: Don't check printer driver before loading the categories
	/*alert("{PRINTCATEGORY.HAVENOT_INSTALLED_DRIVER}");*/
}
function showRootDetail(ID){
	ResetChoose();
	document.getElementById("pathTitle").innerHTML=document.getElementById('root_'+ID).innerHTML;
	document.getElementById("catArea").innerHTML=document.getElementById(ID).innerHTML;
	for(var i=1;i<=9;i++){
		if(document.getElementById("path"+i))
			document.getElementById("path"+i).style.display="none";
	}
}
function mouseOver(obj){
	if(obj.style.background.toString()!="#990000" && obj.style.background.toString()!=selectedColor)
		obj.style.background="#e4e4e4";
}
function mouseOut(obj){
	if(obj.style.background.toString()!="#990000" && obj.style.background.toString()!=selectedColor)
	obj.style.background="#FFFFFF";
}
function indexCell(obj){
	try{
		currentID.style.background="#FFFFFF";
	}
	catch(e){
		
	}
	currentID=obj;
	obj.style.background="#fe9900";
}
function loadChildTab(level,cID,isBrand){
	
	currentLevel=level + 1 ;
	numberLevel=currentLevel;
	ResetChoose();
	/*display("{PRINTCATEGORY.LOADING}","ajax_loading");*/
	oXMLHttp = checkXMLHTTP();
	
	var setRequest = typeof(oXMLHttp.setRequestHeader);
	if ( oXMLHttp && setRequest!="undefined" )
	{
		var myQuery = "&cID="+cID+"&level="+currentLevel+'&isBrand='+isBrand;
		orderPost( oXMLHttp, "?sMod=print_category&sAction=loadChildCategory", myQuery, HTTPLoadAllCategory, true );
	}
}
function loadAlphabetTab(level,cID,isBrand){
	currentLevel = level + 1 ;
	numberLevel = currentLevel;
	ResetChoose();
	oXMLHttp = checkXMLHTTP();
	var setRequest = typeof(oXMLHttp.setRequestHeader);
	if ( oXMLHttp && setRequest!="undefined" ){
		var myQuery = "&cID="+cID+"&level="+currentLevel+'&isBrand='+isBrand;
		orderPost( oXMLHttp, "?sMod=print_category&sAction=loadAlphabetCategory", myQuery, HTTPLoadAllCategory, true );
	}
}

function HTTPLoadAllCategory(){
   if ( typeof(oXMLHttp)==='undefined' )
       return;
    // Return status of XMLHttp object
    if ( oXMLHttp.readyState==4 )
    {
        // if oXMLHttp.status is OK
        if ( oXMLHttp.status==200 )
        {
			sRes = ((oXMLHttp.responseText));
			if(currentLevel == 1){
				display(sRes,"catArea");
			}else{
				var childLevel=currentLevel-1;
				try{
					var obj = document.getElementById("level"+childLevel);
					if(obj){
						display(sRes, "level"+childLevel);
					}
				}
				catch(e){
					
				}
			}
			document.getElementById("path"+currentLevel).innerHTML = "/ &nbsp;"  + document.getElementById("tab"+currentLevel).innerHTML + "&nbsp;";
			document.getElementById("path"+currentLevel).style.display="inline";
		}
		if ( oXMLHttp.status==404)
        {
            alert("Page not found");
        }
    }

}
function loadCurrentTab(level,cID,isBrand){
	goBackTab=level;
	numberLevel=level;
	for(var i=level+1;i<=9;i++){
		//document.getElementById("path"+i).style.display="none";
		$("tab"+i).hide();
	}
	ResetChoose();
	
	/*display("{PRINTCATEGORY.LOADING}","ajax_loading");*/
	oXMLHttp = checkXMLHTTP();
	var setRequest = typeof(oXMLHttp.setRequestHeader);
	if ( oXMLHttp && setRequest!="undefined" )
	{
		var myQuery = "&cID="+cID+"&level="+level+"&isBrand="+isBrand;
		orderPost( oXMLHttp, "?sMod=print_category&sAction=loadCurrentTab", myQuery, HTTPLoadCurrentTab, true );
	}
}
function HTTPLoadCurrentTab()
{
   if ( typeof(oXMLHttp)==='undefined' )
       return;
    // Return status of XMLHttp object
    if ( oXMLHttp.readyState==4 )
    {
        // if oXMLHttp.status is OK
        if ( oXMLHttp.status==200 )
        {
			sRes = ((oXMLHttp.responseText));
			if(goBackTab==0){
				display(sRes,"catArea");
			}
			else{
				var childLevel=goBackTab;
				try{
					var obj = document.getElementById("level"+childLevel);
					if(obj){
						display(sRes,"level"+childLevel);
					}
				}
				catch(e){
					
				}
			}
		}
		document.body.style.cursor = 'default';
		/*display("","ajax_loading");*/
        if ( oXMLHttp.status==404)
        {
            alert("Page not found");
        }
    }

}
function PageNav(page,cID,level){
	/*display("{PRINTCATEGORY.LOADING}","ajax_loading");*/
	oXMLHttp = checkXMLHTTP();
	var setRequest = typeof(oXMLHttp.setRequestHeader);
	if ( oXMLHttp && setRequest!="undefined" )
	{
		var myQuery = "&cID="+cID+"&page="+page+'&level='+level;
		orderPost( oXMLHttp, "?sMod=print_category&sAction=loadPageNav", myQuery, HTTPLoadPageNav, true );
	}
}
function HTTPLoadPageNav()
{
   if ( typeof(oXMLHttp)==='undefined' )
       return;
    // Return status of XMLHttp object
    if ( oXMLHttp.readyState==4 )
    {
        // if oXMLHttp.status is OK
        if ( oXMLHttp.status==200 )
        {
			sRes = ((oXMLHttp.responseText));
			display(sRes,"brandDiv");
		}
		/*display("","ajax_loading");*/
        if ( oXMLHttp.status==404)
        {
            alert("Page not found");
        }
    }

}
function displayNavi(){
	document.getElementById("navi").style.display = "inline";
	document.getElementById("overlay").style.display = "inline";
}
function hideNavi(){
	document.getElementById("navi").style.display = "none";
	document.getElementById("overlay").style.display = "none";
}
function ResetChoose(){
	document.getElementById("printButton").style.display="none";
	selectedYahooID="";
}
function selectCate(obj,yahooID){
	try{
		catSelected.style.background="#FFFFFF";
	}
	catch(e){
		
	}
	
	displayNavi();
	catSelected=obj;
	obj.style.background=selectedColor;
	selectedYahooID=yahooID;
}
function ResetChoose(){
	hideNavi();
	selectedYahooID = "";
}
function register(){
	if(selectedYahooID != ""){
		oXMLHttp = checkXMLHTTP();
		var setRequest = typeof(oXMLHttp.setRequestHeader);
                var shop_owner_id = document.getElementById('shop_owner_id').value;
                if(shop_owner_id==0){
                    alert("please choose Shop Owner");
                    hideNavi();
                    return false;
                }
		if ( oXMLHttp && setRequest!="undefined" ){
			var myQuery = "&yahooID=" + selectedYahooID + "&shop_owner_id=" + shop_owner_id;
			orderPost( oXMLHttp, "?sMod=print_category&sAction=do_generate_pro_id", myQuery, HTTPregister, true );
		}
	}else{
		alert("please choose a category at the first");	
	}
}
function HTTPregister()
{
   if ( typeof(oXMLHttp)==='undefined' )
       return;
    // Return status of XMLHttp object
    if ( oXMLHttp.readyState==4 ) {
        // if oXMLHttp.status is OK
        if ( oXMLHttp.status == 200 ) {
			sRes = ((oXMLHttp.responseText));
			
			display(sRes, "test");
			frm = document.frmPrint;
			PID = frm.PID.value;
			YID = frm.YID.value;
			CName = frm.CName.value;
			BarCode = frm.BarCode.value;
			DPrint = frm.DPrint.value;
			hideNavi();
			alert("{TEXT.register_success}");
			
		}
		if ( oXMLHttp.status==404){
            alert("Page not found");
        }
    }

}
function printLabel(){
	if(isDriverInstalled==false){
		alert("{PRINTCATEGORY.HAVENOT_INSTALLED_DRIVER}");
		return false;
	}
	if(selectedYahooID!=""){
		display("Label is being printed. Please wait for a while...","ajax_loading");
		oXMLHttp = checkXMLHTTP();
		var setRequest = typeof(oXMLHttp.setRequestHeader);
		if ( oXMLHttp && setRequest!="undefined" )
		{
			var myQuery = "&yahooID=" + selectedYahooID;
			orderPost( oXMLHttp, "?sMod=print_category&sAction=do_generate_pro_id", myQuery, HTTPPrint, true );
		}
                hideNavi();
	}
	else{
		alert("please choose a category at the first");	
	}
}
function HTTPPrint(){
   if ( typeof(oXMLHttp) === 'undefined' )
       return;
    // Return status of XMLHttp object
    if ( oXMLHttp.readyState==4 ){
        // if oXMLHttp.status is OK
        if ( oXMLHttp.status==200 ){
			sRes = ((oXMLHttp.responseText));
			display(sRes,"test");
			try{
				frm=document.frmPrint;
				PID=frm.PID.value;
				YID=frm.YID.value;
				CName=frm.CName.value;
				BarCode=frm.BarCode.value;
				DPrint=frm.DPrint.value;
				do_preview(PID,YID,CName,BarCode,DPrint,'');
			}catch(e){
				alert('Print fail, please try it again');
			}
		}
		display("","ajax_loading");
        if ( oXMLHttp.status==404){
            alert("Page not found");
        }
    }

}

function HTTPdisplay()
{
   if ( typeof(oXMLHttp)==='undefined' )
       return;
    // Return status of XMLHttp object
    if ( oXMLHttp.readyState==4 )
    {
        // if oXMLHttp.status is OK
        if ( oXMLHttp.status==200 )
        {
			sRes = ((oXMLHttp.responseText));
			display(sRes,"test");
			try{
				frm=document.frmPrint;
				PID=frm.PID.value;
				YID=frm.YID.value;
				CName=frm.CName.value;
				BarCode=frm.BarCode.value;
				DPrint=frm.DPrint.value;
				do_preview(PID,YID,CName,BarCode,DPrint,'');
			}
			catch(e){
				alert('Print fail, please try it again');
			}
		}
		/*display("","ajax_loading");*/
        if ( oXMLHttp.status==404)
        {
            alert("Page not found");
        }
    }

}
$(document).ready(function(){
	$('.cTopNav').corner("round top 5px");
	$('.cLeftNav').corner("round left 5px");
	$('.itemDiv').corner("5px");
	$('.navi_item').corner("5px");
	$('.category_tab').hover( 
						function() { 
							$(this).addClass("category_tab_hover");
						},
						function() { 
							$(this).removeClass("category_tab_hover");
						}
						);
	$('.itemDiv').hover( 
						function() { 
							$(this).addClass("itemDiv_hover");
						},
						function() { 
							$(this).removeClass("itemDiv_hover");
						}
						);	
	$('.cTopNav').hover( 
						function() { 
							$(this).addClass("cTopNav_hover");
						},
						function() { 
							$(this).removeClass("cTopNav_hover");
						}
						);	
	$('.cLeftNav').hover( 
						function() { 
							$(this).addClass("cLeftNav_hover");
						},
						function() { 
							$(this).removeClass("cLeftNav_hover");
						}
						);																	

});
function changeUser(){
    var frm = document.frmUser;
    frm.action = "?sMod=print_category&userID="+frm.shop_owner_id.value;
    frm.submit();
}
</script>
<div id="overlay" onclick="hideNavi()"></div>
<div id="ajax_loading"></div>
<!-- BEGIN: admin_role-->
<form action="" method="post" name="frmUser">
<div style="float:right;padding-bottom: 5px;">
{MANAGER.shop_owner}
<select name="shop_owner_id" id="shop_owner_id" onchange="changeUser()">
    <option value="0">--- Select One ---</option>
    <!-- BEGIN: shop_owner-->
    <option value="{admin.admin_id}" {admin.admin_select}>{admin.admin_fullname} - {admin.admin_username} </option>
    <!-- END: shop_owner-->
</select>
</div>
</form>
<!-- END: admin_role-->
<!-- BEGIN: shop_owner_role-->
<input name="shop_owner_id" id="shop_owner_id" type="hidden" value="{shop_owner_id}">
<!-- END: shop_owner_role-->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0" class="TopPanel">
        <tr>
          <!-- BEGIN: top_panel-->
          <td style="padding-left:3px;height: 100%"  align="center"><div style="height:25px" onclick="showRootDetail('{topCate.product_category_id}'); indexCell(this);" id="root_{topCate.product_category_id}" class="cTopNav">{topCate.product_category_name}</div></td>
          <!-- END: top_panel-->
        </tr>
      </table></td>
  </tr>
  <tr>
    <td style="padding:5px" valign="top"><div id="catArea"></div>
      <div id="navi">
        <div class="navi_item" id="registerButton" onclick="register()">{FORM.register}</div>
        <div class="navi_item" id="printButton" onclick="printLabel()">{FORM.print}</div>
        <div class="navi_item" id="cancelButton" onclick="hideNavi()">{FORM.cancel}</div>
      </div>
      <div id="test"></div></td>
  </tr>
</table>
<script type="text/javascript">
	//loadAlphabetTab(0, {default_category_id}, 0);
</script>
<div id="test"></div>
<div id="listContent"></div>
<!-- BEGIN: detail-->
<div id="{detail.product_category_id}" style="display:none" >
  <!-- BEGIN: list-->
  <div  class="itemDiv" onclick="{list.javaFunction}">{list.product_category_name}</div>
  <!-- END: list-->
  <!-- BEGIN: list_notChild-->
  <div  class="itemDiv" onclick="selectCate(this,'{list.product_category_yahoo_id}')" >{list.product_category_name}</div>
  <!-- END: list_notChild-->
</div>
<!-- END: detail-->

<!-- BEGIN: detail_alphabet-->
<div id="{detail.product_category_id}" style="display:none" >
  <!-- BEGIN: list-->
  <div  class="itemDiv" onclick="{list.javaFunction};">{list.product_category_name}</div>
  <!-- END: list-->
  <!-- BEGIN: list_notChild-->
  <div  class="itemDiv" onclick="selectCate(this,'{list.product_category_yahoo_id}')" >{list.product_category_name}</div>
  <!-- END: list_notChild-->
</div>
<!-- END: detail_alphabet-->

